using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using ObjectLib;

namespace ObjectParser
{
	/// <summary>
	/// Summary description for ProjPropertiesDialog.
	/// </summary>
	public class ProjPropertiesDialog : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.Label label8;
		private System.Windows.Forms.Label label9;
		private System.Windows.Forms.TextBox textSky;
		private System.Windows.Forms.TextBox textWater;
		private System.Windows.Forms.TextBox textFoliage;
		private System.Windows.Forms.TextBox textDirtOrMud;
		private System.Windows.Forms.TextBox textRock;
		private System.Windows.Forms.TextBox textAnimals;
		private System.Windows.Forms.TextBox textManmadeObjects;
		private System.Windows.Forms.TextBox textPeople;
		private System.Windows.Forms.Button butOK;
		private System.ComponentModel.Container components = null;
		private System.Windows.Forms.ComboBox comboCategory;
		private System.Windows.Forms.RichTextBox rtbSearchText;
		private System.Windows.Forms.Label label10;
		public ObjectParserData Opd;

		public ProjPropertiesDialog(ObjectParserData Opd)
		{
			InitializeComponent();

			this.Opd = Opd;

			ImageCategory[] vals = (ImageCategory[])Enum.GetValues(typeof(ImageCategory));
			this.comboCategory.Items.Clear();
			for(int i=0; i<vals.Length; i++)
				this.comboCategory.Items.Add(vals[i]);
			this.comboCategory.SelectedItem = Opd.ImageCat.ImageCategory;
			this.textSky.Text = Convert.ToString(Opd.ImageCat.Sky);
			this.textWater.Text = Convert.ToString(Opd.ImageCat.Water);
			this.textFoliage.Text = Convert.ToString(Opd.ImageCat.Foliage);
			this.textDirtOrMud.Text = Convert.ToString(Opd.ImageCat.DirtOrMud);
			this.textRock.Text = Convert.ToString(Opd.ImageCat.Rock);
			this.textAnimals.Text = Convert.ToString(Opd.ImageCat.Animals);
			this.textManmadeObjects.Text = Convert.ToString(Opd.ImageCat.ManmadeObjects);
			this.textPeople.Text = Convert.ToString(Opd.ImageCat.People);
			this.rtbSearchText.Text = Opd.SearchText;

			this.DialogResult = DialogResult.Cancel;
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.label1 = new System.Windows.Forms.Label();
			this.comboCategory = new System.Windows.Forms.ComboBox();
			this.label2 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.label4 = new System.Windows.Forms.Label();
			this.label5 = new System.Windows.Forms.Label();
			this.label6 = new System.Windows.Forms.Label();
			this.label7 = new System.Windows.Forms.Label();
			this.label8 = new System.Windows.Forms.Label();
			this.label9 = new System.Windows.Forms.Label();
			this.textSky = new System.Windows.Forms.TextBox();
			this.textWater = new System.Windows.Forms.TextBox();
			this.textFoliage = new System.Windows.Forms.TextBox();
			this.textDirtOrMud = new System.Windows.Forms.TextBox();
			this.textRock = new System.Windows.Forms.TextBox();
			this.textAnimals = new System.Windows.Forms.TextBox();
			this.textManmadeObjects = new System.Windows.Forms.TextBox();
			this.textPeople = new System.Windows.Forms.TextBox();
			this.butOK = new System.Windows.Forms.Button();
			this.rtbSearchText = new System.Windows.Forms.RichTextBox();
			this.label10 = new System.Windows.Forms.Label();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(0, 8);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(144, 23);
			this.label1.TabIndex = 10;
			this.label1.Text = "Category:  ";
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// comboCategory
			// 
			this.comboCategory.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.comboCategory.Location = new System.Drawing.Point(152, 8);
			this.comboCategory.Name = "comboCategory";
			this.comboCategory.Size = new System.Drawing.Size(128, 21);
			this.comboCategory.TabIndex = 0;
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(0, 40);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(144, 23);
			this.label2.TabIndex = 2;
			this.label2.Text = "Sky (1 or 2):  ";
			this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(0, 72);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(144, 23);
			this.label3.TabIndex = 3;
			this.label3.Text = "Water (1 or 2):  ";
			this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(0, 104);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(144, 23);
			this.label4.TabIndex = 4;
			this.label4.Text = "Foliage (1 or 2):  ";
			this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(0, 136);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(144, 23);
			this.label5.TabIndex = 5;
			this.label5.Text = "Dirt or Mud (1 or 2):  ";
			this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label6
			// 
			this.label6.Location = new System.Drawing.Point(0, 168);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(144, 23);
			this.label6.TabIndex = 6;
			this.label6.Text = "Rock (1 or 2):  ";
			this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label7
			// 
			this.label7.Location = new System.Drawing.Point(0, 200);
			this.label7.Name = "label7";
			this.label7.Size = new System.Drawing.Size(144, 23);
			this.label7.TabIndex = 7;
			this.label7.Text = "Animals (1 or 2):  ";
			this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label8
			// 
			this.label8.Location = new System.Drawing.Point(0, 232);
			this.label8.Name = "label8";
			this.label8.Size = new System.Drawing.Size(144, 23);
			this.label8.TabIndex = 8;
			this.label8.Text = "Manmade Objects (1 or 2):  ";
			this.label8.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label9
			// 
			this.label9.Location = new System.Drawing.Point(0, 264);
			this.label9.Name = "label9";
			this.label9.Size = new System.Drawing.Size(144, 23);
			this.label9.TabIndex = 9;
			this.label9.Text = "People (1 or 2):  ";
			this.label9.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// textSky
			// 
			this.textSky.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.textSky.Location = new System.Drawing.Point(152, 40);
			this.textSky.Name = "textSky";
			this.textSky.Size = new System.Drawing.Size(128, 20);
			this.textSky.TabIndex = 1;
			this.textSky.Text = "";
			// 
			// textWater
			// 
			this.textWater.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.textWater.Location = new System.Drawing.Point(152, 72);
			this.textWater.Name = "textWater";
			this.textWater.Size = new System.Drawing.Size(128, 20);
			this.textWater.TabIndex = 2;
			this.textWater.Text = "";
			// 
			// textFoliage
			// 
			this.textFoliage.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.textFoliage.Location = new System.Drawing.Point(152, 104);
			this.textFoliage.Name = "textFoliage";
			this.textFoliage.Size = new System.Drawing.Size(128, 20);
			this.textFoliage.TabIndex = 3;
			this.textFoliage.Text = "";
			// 
			// textDirtOrMud
			// 
			this.textDirtOrMud.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.textDirtOrMud.Location = new System.Drawing.Point(152, 136);
			this.textDirtOrMud.Name = "textDirtOrMud";
			this.textDirtOrMud.Size = new System.Drawing.Size(128, 20);
			this.textDirtOrMud.TabIndex = 4;
			this.textDirtOrMud.Text = "";
			// 
			// textRock
			// 
			this.textRock.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.textRock.Location = new System.Drawing.Point(152, 168);
			this.textRock.Name = "textRock";
			this.textRock.Size = new System.Drawing.Size(128, 20);
			this.textRock.TabIndex = 5;
			this.textRock.Text = "";
			// 
			// textAnimals
			// 
			this.textAnimals.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.textAnimals.Location = new System.Drawing.Point(152, 200);
			this.textAnimals.Name = "textAnimals";
			this.textAnimals.Size = new System.Drawing.Size(128, 20);
			this.textAnimals.TabIndex = 6;
			this.textAnimals.Text = "";
			// 
			// textManmadeObjects
			// 
			this.textManmadeObjects.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.textManmadeObjects.Location = new System.Drawing.Point(152, 232);
			this.textManmadeObjects.Name = "textManmadeObjects";
			this.textManmadeObjects.Size = new System.Drawing.Size(128, 20);
			this.textManmadeObjects.TabIndex = 7;
			this.textManmadeObjects.Text = "";
			// 
			// textPeople
			// 
			this.textPeople.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.textPeople.Location = new System.Drawing.Point(152, 264);
			this.textPeople.Name = "textPeople";
			this.textPeople.Size = new System.Drawing.Size(128, 20);
			this.textPeople.TabIndex = 8;
			this.textPeople.Text = "";
			// 
			// butOK
			// 
			this.butOK.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.butOK.Location = new System.Drawing.Point(8, 400);
			this.butOK.Name = "butOK";
			this.butOK.Size = new System.Drawing.Size(272, 24);
			this.butOK.TabIndex = 10;
			this.butOK.Text = "OK";
			this.butOK.Click += new System.EventHandler(this.butOK_Click);
			// 
			// rtbSearchText
			// 
			this.rtbSearchText.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.rtbSearchText.Location = new System.Drawing.Point(8, 320);
			this.rtbSearchText.Name = "rtbSearchText";
			this.rtbSearchText.Size = new System.Drawing.Size(272, 72);
			this.rtbSearchText.TabIndex = 9;
			this.rtbSearchText.Text = "";
			// 
			// label10
			// 
			this.label10.Location = new System.Drawing.Point(8, 296);
			this.label10.Name = "label10";
			this.label10.TabIndex = 12;
			this.label10.Text = "SearchText:";
			this.label10.TextAlign = System.Drawing.ContentAlignment.BottomLeft;
			// 
			// ProjPropertiesDialog
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(288, 430);
			this.Controls.Add(this.label10);
			this.Controls.Add(this.rtbSearchText);
			this.Controls.Add(this.butOK);
			this.Controls.Add(this.textPeople);
			this.Controls.Add(this.textManmadeObjects);
			this.Controls.Add(this.textAnimals);
			this.Controls.Add(this.textRock);
			this.Controls.Add(this.textDirtOrMud);
			this.Controls.Add(this.textFoliage);
			this.Controls.Add(this.textWater);
			this.Controls.Add(this.textSky);
			this.Controls.Add(this.label9);
			this.Controls.Add(this.label8);
			this.Controls.Add(this.label7);
			this.Controls.Add(this.label6);
			this.Controls.Add(this.label5);
			this.Controls.Add(this.label4);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.comboCategory);
			this.Controls.Add(this.label1);
			this.Name = "ProjPropertiesDialog";
			this.Text = "Project Properties";
			this.ResumeLayout(false);

		}
		#endregion

		private void butOK_Click(object sender, System.EventArgs e)
		{
			bool proceed = true;
			
			ImageCategory imgCat = (ImageCategory)this.comboCategory.SelectedItem;
			string searchText = rtbSearchText.Text;

			int sky = Opd.ImageCat.Sky;
			int water = Opd.ImageCat.Water;
			int foliage = Opd.ImageCat.Foliage;
			int dirt = Opd.ImageCat.DirtOrMud;
			int rock = Opd.ImageCat.Rock;
			int animals = Opd.ImageCat.Animals;
			int man = Opd.ImageCat.ManmadeObjects;
			int people = Opd.ImageCat.People;

			try{	sky = Convert.ToInt32(this.textSky.Text);	}
			catch{	proceed=false;  MessageBox.Show(this, "Value is not an integer."); this.textSky.Focus();	}

			if(proceed)
			{
				try{	water = Convert.ToInt32(this.textWater.Text);	}
				catch{	proceed=false;  MessageBox.Show(this, "Value is not an integer."); this.textWater.Focus();	}
			}
			if(proceed)
			{
				try{	foliage = Convert.ToInt32(this.textFoliage.Text);	}
				catch{	proceed=false;  MessageBox.Show(this, "Value is not an integer."); this.textFoliage.Focus();	}
			}
			if(proceed)
			{
				try{	dirt = Convert.ToInt32(this.textDirtOrMud.Text);	}
				catch{	proceed=false;  MessageBox.Show(this, "Value is not an integer."); this.textDirtOrMud.Focus();	}
			}
			if(proceed)
			{
				try{	rock = Convert.ToInt32(this.textRock.Text);	}
				catch{	proceed=false;  MessageBox.Show(this, "Value is not an integer."); this.textRock.Focus();	}
			}
			if(proceed)
			{
				try{	animals = Convert.ToInt32(this.textAnimals.Text);	}
				catch{	proceed=false;  MessageBox.Show(this, "Value is not an integer."); this.textAnimals.Focus();	}
			}
			if(proceed)
			{
				try{	man = Convert.ToInt32(this.textManmadeObjects.Text);	}
				catch{	proceed=false;  MessageBox.Show(this, "Value is not an integer."); this.textManmadeObjects.Focus();	}
			}
			if(proceed)
			{
				try{	people = Convert.ToInt32(this.textPeople.Text);	}
				catch{	proceed=false;  MessageBox.Show(this, "Value is not an integer."); this.textPeople.Focus();	}
			}

			if(proceed)
			{
				if( sky<0 || sky>ImageCategorizationData._Sky )
				{
					proceed = false;
					MessageBox.Show(this, "Value must be greater than 0 and less than " + Convert.ToString(ImageCategorizationData._Sky));
					this.textSky.Focus();
				}
			}
			if(proceed)
			{
				if( water<0 || water>ImageCategorizationData._Water )
				{
					proceed = false;
					MessageBox.Show(this, "Value must be greater than 0 and less than " + Convert.ToString(ImageCategorizationData._Water) );
					this.textWater.Focus();
				}
			}

			if(proceed)
			{
				if( foliage<0 || foliage>ImageCategorizationData._Foliage )
				{
					proceed = false;
					MessageBox.Show(this, "Value must be greater than 0 and less than " + Convert.ToString(ImageCategorizationData._Foliage));
					this.textFoliage.Focus();
				}
			}
			if(proceed)
			{
				if( dirt<0 || dirt>ImageCategorizationData._DirtOrMud )
				{
					proceed = false;
					MessageBox.Show(this, "Value must be greater than 0 and less than " + Convert.ToString(ImageCategorizationData._DirtOrMud));
					this.textDirtOrMud.Focus();
				}
			}
			if(proceed)
			{
				if( rock<0 || rock>ImageCategorizationData._Rock )
				{
					proceed = false;
					MessageBox.Show(this, "Value must be greater than 0 and less than " + Convert.ToString(ImageCategorizationData._Rock) );
					this.textRock.Focus();
				}
			}
			if(proceed)
			{
				if( animals<0 || animals>ImageCategorizationData._Animals )
				{
					proceed = false;
					MessageBox.Show(this, "Value must be greater than 0 and less than " + Convert.ToString(ImageCategorizationData._Animals));
					this.textAnimals.Focus();
				}
			}
			if(proceed)
			{
				if( man<0 || man>ImageCategorizationData._ManmadeObjects )
				{
					proceed = false;
					MessageBox.Show(this, "Value must be greater than 0 and less than " + Convert.ToString(ImageCategorizationData._ManmadeObjects));
					this.textManmadeObjects.Focus();
				}
			}
			if(proceed)
			{
				if( people<0 || people>ImageCategorizationData._People )
				{
					proceed = false;
					MessageBox.Show(this, "Value must be greater than 0 and less than " + Convert.ToString(ImageCategorizationData._People));
					this.textPeople.Focus();
				}
			}
			if(proceed)
			{
				Opd.ImageCat.ImageCategory = imgCat;
				Opd.SearchText = searchText;
				Opd.ImageCat.Sky = sky;
				Opd.ImageCat.Water = water;
				Opd.ImageCat.Foliage = foliage;
				Opd.ImageCat.DirtOrMud = dirt;
				Opd.ImageCat.Rock = rock;
				Opd.ImageCat.Animals = animals;
				Opd.ImageCat.ManmadeObjects = man;
				Opd.ImageCat.People = people;
				this.DialogResult = DialogResult.OK;
				this.Close();
			}
			else
			{
				this.DialogResult = DialogResult.Cancel;
			}
		}
	}
}
